-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
bin(num). convert ZERO and negative decimal numbers to binary. #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…sistent with built-in python bin(x) function.
…sistent with built-in python bin(x) function.
No doctests?? :-( |
@syedwaleedhyder you can find information about writing doctests on Python's website. |
…s to binary. Consistent with built-in python bin(x) function.
Doctests added :) @cclauss @PatOnTheBack |
@syedwaleedhyder why are you testing |
…s to binary. Consistent with built-in python bin(x) function.
@PatOnTheBack Corrected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@PatOnTheBack How much time LGTM takes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python3 -m doctest -v decimal_to_binary.py finds no doctests. They need to be in the function's first docstring, not in the second. When I get them to run, 6 pass and 3 fail.
…s to binary. Consistent with built-in python bin(x) function.
@cclauss Resolved. All test cases pass now. |
conversions/decimal_to_binary.py
Outdated
@@ -35,9 +34,9 @@ def decimal_to_binary(num): | |||
True | |||
""" | |||
assert type(num) in (int, float) and num == int(num) | |||
|
|||
num = int(num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following test fails...
>>> decimal_to_binary(2.0) == bin(2.0)
True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss bin(2.0) raises exception. And my code also raises exception. But the test still fails. Any idea how to resolve this issue? Can I just hard code the error in the doctests?
`**********************************************************************
File "decimal_to_binary.py", line 34, in main.decimal_to_binary
Failed example:
decimal_to_binary(2.0) == bin(2.0) # doctest: +ELLIPSIS
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.6/doctest.py", line 1330, in __run
compileflags, 1), test.globs)
File "<doctest main.decimal_to_binary[9]>", line 1, in
decimal_to_binary(2.0) == bin(2.0) # doctest: +ELLIPSIS
File "decimal_to_binary.py", line 38, in decimal_to_binary
raise TypeError("'float' object cannot be interpreted as an integer")
TypeError: 'float' object cannot be interpreted as an integer
`
# doctest: +ELLIPSIS as is done at Python/project_euler/problem_10/sol3.py Lines 31 to 38 in 4a5589f
|
The exceptions do not have to be en exact match as long as the exception type and exception string are the same. |
Are we ready to merge? |
I think so. Still have a final look @cclauss . |
|
Thanks for your patience and persistence! |
Liked to work with you. Thanks. @cclauss |
…gorithms#1093) * bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * Added doctests. bin(num) can convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function. * doctests still failing. * Doctests added.
Fixes #1090
bin(num) in decimal_to_binary.py can now convert ZERO and negative decimal numbers to binary. Consistent with built-in python bin(x) function.